package com.yangcangclub.commons.utils;

import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * 对象工具类
 *
 * @author Humn Chou
 * @version 2013-10-24
 * 
 */
public final class ObjectUtils {

	public static boolean isNull(Object obj) {
		return null == obj;
	}
	
	public static boolean isNotNull(Object obj) {
		return null != obj;
	}
	
	public static boolean arrayIsNotNull(Object[] obj) {
		if(isNotNull(obj) && obj.length > 0) {
			return true;
		}
		return false;
	}
	
	public static boolean mapIsNotNull(Map obj) {
		if(isNotNull(obj) && obj.size() > 0) {
			return true;
		}
		return false;
	}
	
	public static String convertObjToStringArray(Object[] obj) {
		StringBuffer str = new StringBuffer();
		str.append("{");
		if(arrayIsNotNull(obj)) {
			for (Object object : obj) {
				str.append(object);
				str.append(",");
			}
		}
		str.append("}");
		return str.toString();
	}
	
	public static boolean hasItInMap(String key,Map map) {
		if(!StringUtils.hasLength(key))
			return false;
		if(mapIsNotNull(map) && null != map.get(key)) {
			return true;
		}
		return false;
	}

	public static int  objToInt(Object obj) {
		int num = 0;
		if(isNull(obj)){
			num = 0;
		}else if(isNotNull(obj)) {
			return  (int)obj;
		}else {
			num =0;
		}
		return num;
	}

	public static long  objToLong(Object obj) {
		long num = 0;
		if(isNotNull(obj)) {
			return  (long)obj;
		}else {
			num =0;
		}
		return num;
	}

	public static void main(String[] args) {

	}


}
